<?php

class Admin_Model_DbTable_Admin extends Zend_Db_Table_Abstract
{

    protected $_name = 'admins';

    public function getAllAdmin(){
    	return $this->fetchAll();
    }
    
    public function getAdminByID($adminID){
    	return $this->fetchRow("admin_id = $adminID");
    }
    
    public function addAdmin($aUserName,$aPass,$aName,$aPhone,$aEmail,$role,$stt){
    	$dataAdmin = array(
    			"admin_username"=>$aUserName,
    			"admin_password"=>$aPass,
    			"admin_name"=>$aName,
    			"admin_phone"=>$aPhone,
    			"admin_email"=>$aEmail,
    			"role"=>$role,
    			"status"=>$stt
    			);
    	return $this->insert($dataAdmin);
    }
    
    public function updateAdmin($aID,$aUserName,$aPass,$aName,$aPhone,$aEmail,$role,$stt){
    	$dataAdmin = array(
    			"admin_username"=>$aUserName,
    			"admin_password"=>$aPass,
    			"admin_name"=>$aName,
    			"admin_phone"=>$aPhone,
    			"admin_email"=>$aEmail,
    			"role"=>$role,
    			"status"=>$stt
    			);
    	return $this->update($dataAdmin, "admin_id = $aID");
    }
    
    public function delAdmin($aID){
    	return $this->delete("admin_id = $aID");
    }
    
    public function checkUserName($uName){
    	return $this->fetchRow("admin_username = $uName");
    }
    
    public function changeStt($adminID){
    	$admin = $this->fetchRow("admin_id = $adminID");
    	if($admin["status"] == 0){
    		return $this->update(array("status"=>1), "admin_id = $adminID");
    	}else{
    		return $this->update(array("status"=>0), "admin_id = $adminID");
    	}
    }
}

